package com.goldplusgold.support.lib.base.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;

/**
 * Created by Administrator on 2017/8/7.
 */

public abstract class BaseNetWorkFragment extends BaseFragment {

    private List<Call> callList ;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        callList = new ArrayList<Call>();
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        cancelAll();
        clearCallList();
    }

    public void addCall(Call call){
        callList.add(call) ;
    }

    public void addAllCall(List<Call> calls){
        callList.addAll(calls);
    }

    public void cancel(Call call){
        for(Call c :callList){
            if(c == call){
                c.cancel();
            }
        }
    }

    public void cancelAll(){
        for(Call c : callList){
            c.cancel();
        }

    }

    public void clearCallList(){
        callList.removeAll(callList);
    }

}
